#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    bool vis[20];
    vector<vector<int>> ans;
    int len;
    vector<vector<int>> permute(vector<int>& nums) {
        vector<int> tmpVt;
        len = nums.size();
        _permute(nums, tmpVt, nums.size());
        return move(ans);
    }

    void _permute(vector<int>& nums, vector<int>& tmpVt, int count)
    {
        if (count == 0) {
            ans.push_back(tmpVt);
            return;
        }
        for (int i = 0; i < len; i++) {
            if (!vis[i]) {
                tmpVt.push_back(nums[i]);
                vis[i] = true;
                _permute(nums, tmpVt, count - 1);
                tmpVt.pop_back();
                vis[i] = false;
            }
        }
    }
};

class Solution {
public:

    vector<vector<int>> ans;
    int len;
    vector<vector<int>> subsets(vector<int>& nums) {
        vector<int> tmpVt;
        len = nums.size();
        _subsets(nums, tmpVt, 0);
        return move(ans);
    }

    void _subsets(vector<int>& nums, vector<int>& tmpVt, int posi)
    {
        ans.push_back(tmpVt);
        for (int i = posi; i < len; i++) {
            tmpVt.push_back(nums[i]);
            _subsets(nums, tmpVt, i + 1);
            tmpVt.pop_back();
        }
    }
};